package com.lj.dao;

import com.lj.po.Blog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lj
 * @Description: ArchiveRepository
 * @date 2020-10-05 22:03
 * @QQ 851477108
 */

@Repository
public interface ArchiveRepository extends JpaRepository<Blog,Long> {

    //查询所有年份，并把博客根据年份分组,降序输出
    @Query("select function('date_format',b.updateTime,'%Y') as year from Blog b group by function('date_format',b.updateTime,'%Y') order by year desc")
    List<String> findGroupYear();

    //根据年份查询博客
    @Query("select b from Blog b where function('date_format',b.updateTime,'%Y') = ?1")
    List<Blog> findByYear(String year);
}
